﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Fashion.Models;

namespace Fashion.ViewModels
{
    public class OrderDetailsModel
    {
        public OrderDetail orderDetails { get; set; }
        public string productName;
        public string size;
        public string color;
        public string coupon;
        public string control;

        private FashionEntities1 fashionDB = new FashionEntities1();

        public OrderDetailsModel(int orderID)
        {
            var orderModel = fashionDB.OrderDetails.Single(o => o.OrderID == orderID);
            this.orderDetails = (OrderDetail)orderModel;

            var product = fashionDB.Products.Single(p => p.ProductID == orderDetails.ProductID);
            if (product.Sex == "female")
                this.control = "Women";
            else
                this.control = "Men";
            this.productName = product.ProductName;

            var color = fashionDB.Colors.Single(c => c.ColorID == orderDetails.ColorID);
            this.color = color.Name;

            var size = fashionDB.Sizes.Single(s => s.SizeID == orderDetails.SizeID);
            this.size = size.Name;

            if (orderDetails.CouponID != null)
            {
                var coupon = fashionDB.Coupons.Single(c => c.CouponID == orderDetails.CouponID);
                this.coupon = coupon.Description;
            }
            else
                this.coupon = "N/A";
        }
    }
}